package com.buyuphk.buyupdeskproject;


import java.io.File;
import java.sql.*;

/**
 * author: JianfeiMa
 * email: majianfei93@163.com
 * created date: 2019-11-26 10:12
 */
public class MySQLiteHelper {
    private Connection connection;

    public MySQLiteHelper(Connection connection) {
        this.connection = connection;
    }

    public void create(String[] urls) {

        try {
            Statement statement = connection.createStatement();
            for (int i = 0; i < urls.length; i ++) {
                File file = new File(urls[i]);
                String sql = "insert into files(file_name) values ('" + file.getName() + "')";
                int executeUpdateResult = statement.executeUpdate(sql);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public boolean read(String fileName) {
        boolean result = false;
        try {
            PreparedStatement preparedStatement = connection.prepareStatement("select * from files where file_name = ?");
            preparedStatement.setString(1, fileName);
            ResultSet resultSet = preparedStatement.executeQuery();
            result = resultSet.next();
        } catch (SQLException sqlException) {
            sqlException.printStackTrace();
        }
        return result;
    }

    public void update() {

    }

    public void delete() {

    }
}
